package dm.ass2.user.io;

/**
 * A pair containing a number of items and sum of ratings of a specific item cluster
 * and the sum of ratings, per a specific user.
 * 
 * @author yaron
 *
 */
public class CBElement {
	
	private int ratingsCounter;
	private float ratingsSum;
	
	public CBElement(int ratingsCounter, float ratingsSum) {
		super();
		this.ratingsCounter = ratingsCounter;
		this.ratingsSum = ratingsSum;
	}

	public int getRatingsCounter() {
		return ratingsCounter;
	}

	public float getRatingsSum() {
		return ratingsSum;
	}
	
	/**
	 * Increment the ratings counter.
	 * 
	 */
	public void increment() {
		increment(1);
	}
	
	public void increment(int i) {
		ratingsCounter += i;
	}
	
	/**
	 * add to the ratings sum
	 * 
	 * @param rating
	 */
	public void addToSum(double rating) {
		ratingsSum += rating;
	}
	
	/**
	 * return average rating.
	 * 
	 * @return
	 */
	public float avg() {
		float avg = 0f;
		
		if (ratingsCounter != 0) {
			avg = ratingsSum / ratingsCounter;
		}
			
		return avg;
	}
	
}
